
#include "TCPServer.hpp"
#include "Http.hpp"
#include "Socket.hpp"

Response Login(Request req)
{
    std::string text = req.GetRequestBody();
    std::string content = "<html><head><meta charset='UTF-8'></head><h1>请求服务:login\r\n参数："
     + text + "</h1></html>";
    Response resp;
    resp.AddCode(200, "OK");
    resp.AddBodyText(content);
    return resp;
}


int main(int args, char *argv[])
{
    if (args < 2)
    {
        LOG(FATAL, "too few arguments!\n");
        exit(0);
    }
    uint16_t port = std::stoi(argv[1]);

    HttpService service;
    service.InsertService("wwwroot/login", Login);

    TCPServer server(std::bind(&HttpService::HandleHttpRequest, &service, std::placeholders::_1),
                     port);
    server.Loop();
}